<template>
	<div class="review">
		<reviewList v-bind:reviewList="reviewList"></reviewList>
	</div>
</template>

<script> 
	import reviewList from '@/components/index'
	export default {
		data(){
			return{
				id:'',
				reviewList:[],
				offset:0
			}
		},
		components: {
    		reviewList
  		},
		onLoad:function(options){
			this.id=options.id;
			wx.setNavigationBarTitle({
				title: "影片评论" 
			});
			this.getrReviewList();
		},
		onReachBottom: function() {
			wx.showLoading({
				title: '玩命加载中',
			})
			this.offset += 10;
			this.getrReviewList();
		},
		methods:{
			getrReviewList:function(){
				var that = this;
				wx.request({
					url:"https://m.maoyan.com/comments.json",
					data:{movieid:that.id,limit:10,offset:that.offset},
					success:function(res){
						var cmts = res.data.data.CommentResponseModel.cmts;
						for(var i=0;i<cmts.length;i++){
							var arr = that.showstar(cmts[i].score);
							cmts[i].score = arr;
						}
						if(that.offset === 0) {
							that.reviewList = cmts;
						}else{
							that.reviewList = that.reviewList.concat(cmts);
						}
						console.log(that.reviewList);
						wx.hideLoading();
					}
					
				})
			},
			showstar:function(score){
				var arr=[];
				if((score/0.5)%2==0){
					for(var i=0;i<5;i++){
						if(i<score){
							arr.push('stargary')
						}else{
							arr.push('starfull')
						}
					}
				}else{
					for(var i=0;i<5;i++){
						if(i<score-0.5){
       						arr.push('stargary');
	      				}else if(i==(score-0.5)){
	       					arr.push('starban');
	      				}else{
	       					arr.push('starfull');
	      				}
					}
				}
				return arr;
			},
		}
		
	}
</script>

<style>
</style>